package com.tx.txlibs;


import android.content.Context;
import android.widget.Toast;


public class TxUtils {

    private static final String TAG = "TxUtils";

    // 构造方法私有化 不允许new对象
    private TxUtils() {
    }

    // Toast对象
    private static Toast toast = null;

    /**
     * 显示当前Toast, 马上停止上一个Toast
     */
    public static void showText(Context context, String text) {

        if (toast != null) // 关掉上一个
        {
            toast.cancel();
        }
        toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); // 新建一个Toast. 如果是用原来的Toast, 重新setText会有问题, 有时候显示不出来.
        toast.show();
    }


    //字符序列转换为16进制字符串
    public static String bytesToHexString(byte[] src) {
        StringBuilder stringBuilder = new StringBuilder("");
        if (src == null || src.length <= 0) {
            return null;
        }
        char[] buffer = new char[2];
        for (int i = 0; i < src.length; i++) {
            buffer[0] = Character.forDigit((src[i] >>> 4) & 0x0F, 16);
            buffer[1] = Character.forDigit(src[i] & 0x0F, 16);
            // System.out.println(buffer);
            stringBuilder.append(buffer);
        }
        return "0x"+stringBuilder.toString().toUpperCase();
    }
}